﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Xml.Linq;

namespace BurnSystems.Gpx
{
    /// <summary>
    /// trk represents a track - an ordered list of points describing a path. 
    /// </summary>
    public class GpxTrack : GpxNamedElement
    {
        /// <summary>
        /// Initializes a new instance of the GpxTrack class.
        /// </summary>
        /// <param name="node">Node to be used for track</param>
        public GpxTrack(XElement node)
            : base(node)
        {
        }

        /// <summary>
        /// Gets a list of tracksegments
        /// </summary>
        public IList<GpxTrackSegment> TrackSegments
        {
            get
            {
                return this.node
                    .Elements(GpxDocument.FullyQualifiedNS + "trkseg")
                    .Select(x => new GpxTrackSegment(x))
                    .ToList()
                    .AsReadOnly();
            }
        }

        /// <summary>
        /// Gets the bounding box
        /// </summary>
        public BoundingBox BoundingBox
        {
            get
            {
                return this.TrackSegments.Select(x => x.BoundingBox).Max();
            }
        }
    }
}
